package handlers

import (
	"gin_erik/internal/repositories"
	"gin_erik/pkg/utils"
	"github.com/gin-gonic/gin"
	"net/http"
)

type UsersHandler struct {
	userRepo repositories.UserRepository
}

func NewUsersHandler() *UsersHandler {
	return &UsersHandler{
		userRepo: *repositories.NewUserRepository(),
	}
}
func (h *UsersHandler) GetUsers(c *gin.Context) {
	users := h.userRepo.GetAllUsers()
	utils.SendResponse(c, http.StatusOK, "success", users)
}

// Detail 获取用户详情
// @Summary 获取用户详情
// @Description 根据用户ID获取用户详情
// @Tags users
func (h *UsersHandler) Detail(c *gin.Context) {
	id := c.Param("id")
	user, err := h.userRepo.GetUserByID(id)
	if err != nil {
		utils.SendResponse(c, http.StatusInternalServerError, err.Error(), nil)
		return
	}
	utils.SendResponse(c, http.StatusOK, "success", user)
}
